;===========================================================
;PREFIX.COM - prefixes each line of input with whatever is 
;             on the command-line and writes the result to 
;             the standard o/p.
;===========================================================

;-----------------------------------------------------------
; mnemonic                   comment
;-----------------------------------------------------------
 SUB     SI,SI              ; SI=0 saya prefix to be
                            ; written
 MOV     AH,3F              ; select Read file or device
                            ; function
 MOV     BX,0000            ; BX gets handle for STDIN
 MOV     CX,0001            ; read 1 character
 MOV     DX,0081            ; read into space before
                            ; command tail
 INT     21                 ; call DOS function
 JB      014E               ; error? Get out!
 CMP     AX,0000            ; length 0? ...
 JZ      014E               ; ... get out!
 CMP     BYTE PTR [0081],1B ; is it end-of-file? ...
 JZ      014E               ; ... if so, get out!
 CMP     BYTE PTR [0081],0A ; is it a line feed? ...
 JZ      0102               ; ... if so, skip it!
 TEST    SI,SI              ; is SI 0?
 JNZ     012B               ; if NOT, don't write prefix
 CALL    0152               ; if SI=0, call write-prefix
                            ; subroutine
 MOV     AH,40              ; select Write file or device
                            ; function
 MOV     BX,0001            ; BX gets handle for STDOUT
 MOV     CX,0001            ; write one character
 MOV     DX,0081            ; write from space before
                            ; command tail
 INT     21                 ; call DOS function
 CMP     BYTE PTR [0081],0A ; was it a line feed? ...
 JNZ     0140               ; ... if not, skip next line
 DEC     SI                 ; set SI=0 to get prefix
                            ; written
 CMP     BYTE PTR [0081],0D ; was it a carriage return? ...
 JNZ     0102               ; ... if not, go to next char
 MOV     BYTE PTR [0081],0A ; move a line-feed to
                            ; character-writing spot
 JMP     012B               ; jump back and write it
 MOV     AH,4C              ; select terminate w/ exit
                            ; code function
 INT     21                 ; call DOS function
                            ; write prefix subroutine
 SUB     CX,CX              ; zero out CX
 MOV     CL,[0080]          ; get length of command tail
                            ; in CX
 JCXZ    016E               ; nothing? Skip it!
 MOV     DI,0082            ; DI points to start of
                            ; command tail
 ADD     DI,CX              ; DI points to past end of
                            ; command tail
 DEC     DI                 ; DI points to end of
                            ; command tail
 MOV     AL,20              ; space in AL
 STOSB                      ; put space at end of
                            ; command tail
 MOV     AH,40              ; select Write file or device
                            ; function
 MOV     BX,0001            ; BX gets handle for STDOUT
 MOV     DX,0082            ; DX points to command tail
 INT     21                 ; write the prefix
 INC     SI                 ; SI=1 says prefix already
                            ; written
 RET                        ; return
;-----------------------------------------------------------
